package com.maysham.tripod.dao;

import com.maysham.tripod.model.User;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.List;

@Repository
public class UserDao {
    @Resource
    private MongoTemplate template;

    public User findByUsername(String name) {
        return template.findOne(Query.query(Criteria.where("username").is(name).and("deleted").is(false)), User.class);
    }

    public List<User> findAll() {
        return template.findAll(User.class);
    }

    public void save(User user) {
        template.save(user);
    }
}
